# -*- coding:utf-8 -*-
import configparser


class GetConfig(object):
    def __init__(self, path):
        self.path = path
        self.cfg = configparser.ConfigParser()
        self.cfg.read(self.path, encoding='utf-8')

    def get_database(self, section):
        """
        获取数据库的配置文件
        :param section:
        :return:
        """
        data = dict(self.cfg.items(section))
        # 修改端口号为int类型
        data["port"] = int(data["port"])
        return data

    def get_base_url(self, section):
        """
        获取base_url配置
        :param section:
        :return:
        """
        data = dict(self.cfg.items(section))
        return data['base_url']

    def get_message_config(self):
        """
        获取消息相关配置
        :param section:
        :return:
        """

        config_dict = {}
        for section in self.cfg.sections():
            config_dict[section] = {}
            for key, value in self.cfg.items(section):
                config_dict[section][key] = value
        return config_dict


if __name__ == '__main__':
    from config.config import *

    print(GetConfig(MESSAGE).get_message_config())